package com.facebookproject.getsuggestitems;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebookproject.R;

public class ItemAdapter extends ArrayAdapter<Item> {

	private List<Item> items;
	public List<Item> getItems(){
		return items;
	}

	public ItemAdapter(Context fragmentMe, int textViewResourceId, List<Item> items) {
		super(fragmentMe, textViewResourceId, items);
		this.items = items;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater infalInflater = (LayoutInflater) getContext()
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = infalInflater.inflate(R.layout.item, null);
		}

		final Item item = items.get(position);
		TextView txtSug = (TextView)v.findViewById(R.id.txtSug);
		ImageView icon = (ImageView)v.findViewById(R.id.icon);

		txtSug.setText(item.getItem_name());
		
		int resID = getContext().getResources().getIdentifier(item.getIcon() ,"drawable", getContext().getPackageName());
		icon.setImageResource(resID);
		return v;
	}
}
